<template>
  <a-row :gutter="10">
    <a-col :md="12" :sm="24">
      <!-- 查询区域 -->
      <div class="table-page-search-wrapper">
        <!-- 搜索区域 -->
        <a-form layout="inline" @keyup.enter.native="searchQuery">
          <a-row :gutter="24">
            <a-col :md="12" :sm="8">
              <a-form-item label="名称" :labelCol="{span: 5}" :wrapperCol="{span: 18, offset: 1}">
                <a-input placeholder="请输入名称查询" v-model="queryParam.name"></a-input>
              </a-form-item>
            </a-col>
            <a-col :md="12" :sm="24">
              <a-button type="primary" @click="searchQuery">查询</a-button>
              <a-button style="margin-left: 8px" @click="searchReset">重置</a-button>
            </a-col>
          </a-row>
        </a-form>
      </div>

      <!-- 操作按钮区域 -->
      <div class="table-operator" style="margin-top: 5px">
        <a-button @click="modelFormHandle()" type="primary" icon="plus">新建角色</a-button>
      </div>

      <!-- table区域-begin -->
      <div>
        <div class="ant-alert ant-alert-info" style="margin-bottom: 16px;">
          <i class="anticon anticon-info-circle ant-alert-icon"></i>已选择&nbsp;<a style="font-weight: 600">{{ selectedRowKeys.length }}</a>项&nbsp;&nbsp;
          <a style="margin-left: 24px" @click="onClearSelected">清空</a>
        </div>

        <a-table
            ref="table"
            size="middle"
            bordered
            rowKey="id"
            :columns="columns"
            :dataSource="dataList"
            :pagination="ipagination"
            :loading="loading"
            :rowSelection="{selectedRowKeys: selectedRowKeys, onChange: onSelectChange, type: 'radio'}"
            @change="tableChangeHandle">

        <span slot="action" slot-scope="text, record">
          <a @click="modelFormHandle(record.id)">编辑</a>
          <a-divider type="vertical" />


          <a-dropdown>
            <a class="ant-dropdown-link">
              更多 <a-icon type="down" />
            </a>
            <a-menu slot="overlay">
              <a-menu-item>
                <a-popconfirm title="确定删除吗?" @confirm="() => deleteHandle(record.id)">
                  <a>删除</a>
                </a-popconfirm>
              </a-menu-item>
            </a-menu>
          </a-dropdown>
        </span>

        </a-table>
      </div>
      <!-- table区域-end -->

    </a-col>

    <a-col :md="12" :sm="24">
      <user-form-card ref="userFormCard"></user-form-card>
    </a-col>

    <model-form ref="modelForm" v-if="modelFormVisible" @ok="modalFormOk"></model-form>
  </a-row>
</template>

<script>
import listMixin from '@/mixins/list-mixin'
import modelForm from './model/role-form'
import userFormCard from './model/user-form-card'

export default {
  name: "role",
  mixins: [listMixin],
  components: {
    modelForm,
    userFormCard
  },
  data () {
    return {
      disableMixinCreated: true,
      queryParam: {},
      columns: [
        {
          title: '角色名称',
          align: "center",
          dataIndex: 'name'
        },
        {
          title: '备注',
          align: "center",
          dataIndex: 'remark'
        },
        {
          title: '创建时间',
          dataIndex: 'createDate',
          align: "center",
          sorter: true
        },
        {
          title: '操作',
          dataIndex: 'action',
          scopedSlots: { customRender: 'action' },
          align: "center",
          width: 150
        }
      ],
      url: {
        list: '/sys/role/page',
        delete: '/sys/role'
      }
    }
  },
  methods: {
    onSelectChange (selectedRowKeys, selectionRows) {
      this.selectedRowKeys = selectedRowKeys;
      this.selectionRows = selectionRows;
      this.$refs.userFormCard.queryParam.roleId = selectedRowKeys[0]
      this.$refs.userFormCard.searchQuery()
    },
  }
}
</script>

<style scoped>

</style>
